package com.techsun.datanow.sync.hdfs

import java.util.{Calendar, TimeZone}

import com.techsun.datanow.SHDataSyncApp.getZero_time
import org.apache.commons.lang.StringUtils
import org.apache.spark.sql.SparkSession

/**
 * @Auther Shichao@techsun.com
 * @Date 2021/2/4 17:53
 * @version 1.0.1
 */
object StartApp {
  def main(args: Array[String]): Unit = {
    val cosmosDbEndpoint = args(0);
    val cosmosDbMasterkey = args(1);
    val dateset = if (args.length > 2) args(2) else null;

    //修改时区
    val cal: Calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"))
    val today_zeroTime = getZero_time(cal.getTime);
    cal.add(Calendar.DATE, -1)
    val yestoday_zeroTime = getZero_time(cal.getTime);
    var beginTime = yestoday_zeroTime;
    var endTime = today_zeroTime;

    if (StringUtils.isNotBlank(dateset) && dateset == "t") {
      if (args.length < 6) {
        printf("Parameters count error! There didn't set cycle time")
        System.exit(1)
      }
      beginTime = args(3).toLong
      endTime = args(4).toLong
    }

    val spark = SparkSession
      .builder()
      .appName("Sync_TsrCoupon")
      .config("spark.debug.maxToStringFields", "200")
      .getOrCreate();

     new Sync_TsrCoupon().sync(spark,cosmosDbEndpoint,cosmosDbMasterkey,beginTime,endTime)

    spark.close()
    System.exit(1)
  }

}
